<?php

/**
 * @author     bigface.cc
 * @date       2012-7-8 
 * @version    1.0
 */
//查茶网城市控制器
class links_cityAction extends baseAction
{       
        //显示城市列表
        function index(){
                $links_mod=M('links_city');
                $links_city=$links_mod->order('id DESC')->select();
                $this->assign('links_city',$links_city);
                $this->display();
        }
        //添加城市
        function add(){
                if(isset($_POST['dosubmit'])){
                        $city=D('links_city');
                        $list=$city->select();
                        if($vo=$city->create()){
                                $list=$city->add();
                                if($list!==FALSE){
                                        $this->success("城市添加成功");
                                }else{
                                        $this->error("城市添加失败");
                                }
                        }  else {
                                $this->error($city->getError());
                        }
                }
                $this->display();
        }
        //删除城市
        function del(){
                if((!isset($_GET['id']) || empty($_GET['id'])) && (!isset($_POST['id']) || empty($_POST['id']))){
                        $this->error("请选择你要删除的城市");
                }
                $links_mod=M('links_city');
                if(isset ($_POST['id']) && is_array($_POST['id'])){
                        $links_mod->delete(implode(',', $_POST['id']));
                }else{
                        $links_mod->delete(intval($_POST['id']));
                }
                $this->success(L('operation_success'));
        }
        //编辑城市
        function edit(){
               
                //提交修改信息
                if(isset ($_POST['dosubmit'])){
                        $links_mod=M("links_city");
                        $data=$links_mod->create();
                        $data['name']=$_POST['name'];
                        $data['pre_letter']=$_POST['pre_letter'];
                        $data['pin']=$_POST['pin'];
//                        print_r($data);exit;
                        $rs=$links_mod->where("id=".$_POST['id'])->save($data);
//                        echo $links_mod->getLastSql();exit;
                        if(FALSE!==$rs){
                                $this->success('修改成功',U('links_city/index'),1);
                        }else{
                                $this->error("修改失败",U('links_city/index'));
                        }
                }else{ //显示详细信息
                        $links_mod=M('links_city');
                        if(isset ($_GET['id'])){
                                $cityid=isset($_GET['id']) && intval($_GET['id']) ? intval($_GET['id']) : $this->error(L('please_select').'要编辑的城市');
                        }
                        $city_info=$links_mod->where('id='.$cityid)->find();
                        $this->assign('city_info',$city_info);
                        $this->display();
                }
        }
}
?>
